home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / server / gods.c < prev    next >
C/C++ Source or Header  |  1996-07-24  |  12KB  |  380 lines

  1. /*
  2.  * static char *rcsid_apply_c =
  3.  *   "$Id: gods.c,v 1.4 1996/07/24 07:37:10 master Exp master $";
  4.  */
  5. /*
  6.     CrossFire, A Multiplayer game for X-windows
  7.  
  8.     Copyright (C) 1994 Mark Wedel
  9.     Copyright (C) 1992 Frank Tore Johansen
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.     The author can be reached via e-mail to mwedel@pyramid.com
  26. */
  27.  
  28.  
  29. /* Oct 3, 1995 - Code laid down for initial gods, priest alignment, and 
  30.  * monster race initialization. b.t.
  31.  */
  32.  
  33. #include <global.h>
  34. #include <living.h>
  35. #include <object.h>
  36. #include <spells.h>
  37. #include <sounds.h>
  38. #ifndef __CEXTRACT__
  39. #include <sproto.h>
  40. #endif
  41.  
  42. int 
  43. lookup_god_by_name(char *name) {
  44.   int godnr=0;
  45.   int nmlen = strlen(name);
  46.  
  47.   if(name==NULL || !strcmp(name,"none")) return -1;
  48.   while(strncmp(name,Gods[godnr].name,MIN(strlen(Gods[godnr].name),nmlen))
  49.           && godnr < (NROFGODS - 1)) {
  50.         godnr++;
  51.   }
  52.  
  53.   if(godnr==NROFGODS) godnr=-1;
  54.   return godnr;
  55. }
  56.  
  57. void become_follower (object *op, char *godname) {
  58.   object *exp_obj = op->chosen_skill->exp_obj;
  59.   int godnr = lookup_god_by_name(godname);
  60.  
  61.     if(godnr<0) return;
  62.  
  63.     new_draw_info_format(NDI_UNIQUE|NDI_NAVY,0,op,
  64.        "You become a follower of %s!",godname);
  65.     if(exp_obj->title) { /* get rid of old god */ 
  66.        new_draw_info_format(NDI_UNIQUE,0,op,
  67.            "%s's blessing is withdrawn from you.",exp_obj->title);
  68.        CLEAR_FLAG(exp_obj,FLAG_APPLIED); 
  69.        (void) change_abil(op,exp_obj);
  70.         free_string(exp_obj->title);
  71.     }
  72.  
  73.    /* now change to the new gods attributes to exp_obj */
  74.     exp_obj->title = add_string(godname);
  75.     exp_obj->protected=Gods[godnr].protected; 
  76.     exp_obj->vulnerable=Gods[godnr].vulnerable; 
  77.     exp_obj->path_attuned=Gods[godnr].path_attuned;
  78.     exp_obj->path_repelled=Gods[godnr].path_repelled;
  79.     exp_obj->path_denied=Gods[godnr].path_denied;
  80.  
  81.     new_draw_info_format(NDI_UNIQUE,0,op,
  82.            "You are bathed in %s's aura.",godname);
  83.  
  84.     SET_FLAG(exp_obj,FLAG_APPLIED); 
  85.     (void) change_abil(op,exp_obj);
  86.  
  87.  
  88. /* determine_god() - determines if op worships a god. Returns
  89.  * the godname if they do. In the case of an NPC, if they have
  90.  * no god, we give them a random one. -b.t. 
  91.  */
  92.  
  93. char *determine_god(object *op) {
  94.   int godnr = -1;
  95.  
  96.   if(op->type!= PLAYER && !op->title && QUERY_FLAG(op,FLAG_ALIVE)) { 
  97.       godnr = RANDOM()%NROFGODS; 
  98.       return ((op->title = add_string(Gods[godnr].name)));
  99.   } else {
  100.     if((op->type==PLAYER && op->chosen_skill 
  101.       && op->chosen_skill->exp_obj && op->chosen_skill->exp_obj->title))
  102.            return  op->chosen_skill->exp_obj->title;
  103.   }
  104.   return ("none");
  105.  
  106.  
  107. /* god_intervention() - called from praying() currently. Every
  108.  * once in a while the god will intervene to help the worshiper.
  109.  * Later, this fctn can be used to supply quests, etc for the 
  110.  * priest. -b.t. 
  111.  */
  112.  
  113. void god_intervention(object *op, char *godname) {
  114.   int godnr = lookup_god_by_name(godname); 
  115.   int level=SK_level(op);
  116.  
  117.   /*safety, shouldnt happen */
  118.   if(godnr==-1) return;
  119.  
  120.   new_draw_info(NDI_UNIQUE|NDI_UNIQUE,0,op,"You feel a holy presence!");
  121.  
  122.   /* So, what can we do to help out? We do some minimal checking
  123.    * of the god's attributes to ensure there is a bit of consistency
  124.    * between what happens and what the god can do. We do benefits 
  125.    * in 2 sections. In the first, we check if the god can fix
  126.    * problems of the priest. In the second, rare boons are given.
  127.    * In either case, as soon as the god gives a gift, we return */
  128.  
  129.  
  130.   /* FIRST SECTION */
  131.  
  132.   /* Restore the priest to a better state of grace. */ 
  133.   if(op->stats.grace<0) {
  134.         new_draw_info(NDI_UNIQUE,0,op,"You are returned to a state of grace.");
  135.     op->stats.grace=RANDOM()%10;
  136.     return;
  137.   } 
  138.  
  139.  /* Heal damage */
  140.   if(!(Gods[godnr].path_denied&PATH_RESTORE)) { 
  141.      if(op->stats.hp<op->stats.maxhp) { 
  142.     op->stats.hp=op->stats.maxhp;
  143.         new_draw_info(NDI_UNIQUE,0,op,"A white light surrounds and heals you!");
  144.     return;
  145.      }
  146.   }
  147.  
  148.  /* cure confusion? */
  149.   if(!(Gods[godnr].attacktype&AT_CONFUSION))
  150.     if(cast_heal(op,0,SP_CURE_CONFUSION)) return;
  151.  
  152.  /* remove poison? */
  153.   if(!(Gods[godnr].attacktype&AT_POISON))
  154.     if(cast_heal(op,0,SP_CURE_POISON)) return;
  155.  
  156.  /* Remove cursed/damned items? This is better than the spell, here we
  157.   * allow unapplied items to be uncursed */
  158.   if(!(RANDOM()%2)&&!(Gods[godnr].path_denied&PATH_TURNING)) {
  159.     object *tmp;
  160.     int success = 0;
  161.  
  162.     for (tmp = op->inv; tmp; tmp = tmp->below)
  163.       if (QUERY_FLAG(tmp, FLAG_CURSED)||QUERY_FLAG(tmp, FLAG_DAMNED)) {
  164.           success++;
  165.           if(QUERY_FLAG(tmp, FLAG_DAMNED)) CLEAR_FLAG(tmp, FLAG_DAMNED);
  166.           CLEAR_FLAG(tmp, FLAG_CURSED);
  167.           CLEAR_FLAG(tmp, FLAG_KNOWN_CURSED);
  168.           if (op->type == PLAYER && op->contr->eric_server > 0)
  169.                   esrv_send_item(op, tmp);
  170.        }  
  171.     if (op->type==PLAYER&&success) {
  172.     new_draw_info(NDI_UNIQUE, 0,op, "You feel like someone is helping you.");
  173.     draw_inventory(op);
  174.     return;
  175.     }
  176.   }
  177.  
  178.   /* Fix drained stats? */
  179.   if(!(RANDOM()%2)&&!(Gods[godnr].attacktype&AT_DRAIN)) {
  180.      object *depl;
  181.      archetype *at;
  182.  
  183.      if ((at = find_archetype("depletion"))==NULL) {
  184.         LOG(llevError,"Could not find archetype depletion");
  185.         return;
  186.      }  
  187.      depl = present_arch_in_ob(at, op);
  188.      if (depl!=NULL) {   
  189.         int i;
  190.         new_draw_info(NDI_UNIQUE,0,op,"Shimmering light surrounds and restores you!");
  191.         for (i = 0; i < 7; i++)
  192.             if (get_attr_value(&depl->stats, i)) {
  193.               new_draw_info(NDI_UNIQUE,0,op, restore_msg[i]);
  194.             }
  195.     remove_ob(depl);
  196.     free_object(depl);
  197.         fix_player(op);
  198.         return;
  199.      }
  200.   }
  201.   
  202.   /* Special knowledge of the God? */
  203.   if((!RANDOM()%10)&&!(Gods[godnr].path_denied&PATH_INFO)) { 
  204.       if(strcmp(Gods[godnr].enemy_race,"none")) {
  205.           new_draw_info_format(NDI_UNIQUE,0,op,
  206.         "You are filled with a desire to slay all things which are %s.",
  207.         Gods[godnr].enemy_race);
  208.       return;
  209.       } else if(strcmp(Gods[godnr].aligned_race,"none")) {
  210.           new_draw_info_format(NDI_UNIQUE,0,op,
  211.         "You are feel a bond with all things which are %s.",
  212.         Gods[godnr].aligned_race);
  213.       return;
  214.       } 
  215.   }
  216.  
  217.   /* SECOND SECTION */
  218.  
  219.   /* Now, for the special section. If the priest is in a "state of grace"
  220.    * (ie grace.stats>100&&grace>maxgrace) we get one of the good benefits
  221.    * else, just a "super-blessing" via "holy possession" spell */
  222.  
  223.   /* blessing via "holy possesion" spell */
  224.   if((op->stats.grace<80)||(op->stats.grace<op->stats.maxgrace)) {
  225.      (void) cast_change_attr(op,0,SP_HOLY_POSSESSION);
  226.      return;
  227.   }
  228.  
  229.   /* Enchant/bless your weapon upto priest level/5  */
  230.   if(!(RANDOM()%2)&&QUERY_FLAG(op,FLAG_READY_WEAPON)) {
  231.     object *weapon=NULL;
  232.  
  233.     for(weapon=op->inv;weapon;weapon=weapon->below) 
  234.        if(weapon->type==WEAPON&&QUERY_FLAG(weapon,FLAG_APPLIED)) break;
  235.  
  236.     /* allow the weapon to slay enemies */
  237.     if(weapon && !weapon->slaying&&strcmp("none",Gods[godnr].enemy_race)) {
  238.         char buf[MAX_BUF];
  239.  
  240.     weapon->slaying = add_string(Gods[godnr].enemy_race); 
  241.         new_draw_info(NDI_UNIQUE,0,op,"Your weapon quivers as if struck!"); 
  242.     if(!weapon->title) {
  243.           new_draw_info_format(NDI_UNIQUE,0,op,
  244.              "Your %s now hungers to slay enemies of your god!",
  245.          weapon->name);
  246.       sprintf(buf,"of %s",godname);
  247.       weapon->title=add_string(buf);
  248.           if(op->type==PLAYER) draw_inventory(op);
  249.     }
  250.     return;
  251.     }
  252.  
  253.     /* add the gods attacktype*/
  254.     if(weapon && !(RANDOM()%2)&&!(weapon->attacktype&Gods[godnr].attacktype)) {
  255.         new_draw_info(NDI_UNIQUE,0,op,"Your weapon suddenly glows!");
  256.     weapon->attacktype=weapon->attacktype|Gods[godnr].attacktype;
  257.     return;
  258.     }
  259.  
  260.     /* higher magic value */
  261.     if(weapon && !(RANDOM()%2)&&weapon->magic<(level/5)) {
  262.        new_draw_info(NDI_UNIQUE,0,op,
  263.           "A phosphorescent glow envelops your weapon!");
  264.        weapon->magic++;
  265.        if(op->type==PLAYER) draw_inventory(op);
  266.        return;
  267.     }
  268.   }
  269.  
  270.  /* If they qualify, grant the priest use of a special spell */
  271.  
  272.   if(op->stats.Wis&&op->stats.Wis>25) { 
  273.     int spell=0;
  274.  
  275.    /*generate a random rare clerical spell*/  
  276.     do {
  277.     spell=RANDOM()%NROFREALSPELLS;
  278.     } while(spells[spell].books && !spells[spell].cleric);
  279.  
  280.  
  281.    /* The god will only teach the spell if its not against the nature
  282.     * of the cult, the priest is high enough in level *and* the priest
  283.     * doesnt already know it */
  284.    /* Also, there are some spells which can really disturb playbalance,
  285.     * to keep these out of player hands, we discard any spell which 
  286.     * has PATH_NULL.  
  287.     */
  288.  
  289.     if(!(Gods[godnr].path_denied&spells[spell].path) 
  290.         &&!(Gods[godnr].path_repelled&spells[spell].path) 
  291.     &&!(spells[spell].path&PATH_NULL)
  292.     &&spells[spell].level<=level
  293.     &&!check_spell_known(op,spell)) { 
  294.  
  295. #ifdef SOUND_EFFECTS 
  296.         play_sound_player_only(op->contr, SOUND_LEARN_SPELL); 
  297. #endif   
  298.         new_draw_info_format(NDI_UNIQUE, 0,op,
  299.         "%s grants you use of a special prayer!",godname); 
  300.         op->contr->known_spells[op->contr->nrofknownspells++]=spell; 
  301.         if(op->contr->nrofknownspells == 1) 
  302.             op->contr->chosen_spell=spell; 
  303.         new_draw_info_format(NDI_UNIQUE, 0, op, 
  304.             "Type 'bind cast %s",spells[spell].name); 
  305.         new_draw_info(NDI_UNIQUE, 0,op,"to store the spell in a key."); 
  306.         return;
  307.     } 
  308.   } 
  309.    
  310. /* Last message, sorry charlie, nothing was given except good vibes :) */
  311.   new_draw_info(NDI_UNIQUE, 0,op,"You feel rapture."); 
  312.  
  313. }
  314.  
  315. /* get_god() - returns the gods index in Gods[] array, if the god
  316.  * exists, if not, it returns -1. -b.t.
  317.  */
  318.  
  319. int get_god(object *priest) {
  320.   int godnr=lookup_god_by_name(determine_god(priest)); 
  321.  
  322.   return godnr;
  323. }
  324.  
  325.  
  326. /* tailor_god_spell() - changes the attributes of cone, smite, 
  327.  * and ball spells as needed by the code. Returns false if there
  328.  * was no race to assign to the slaying field of the spell, but
  329.  * the spell attacktype contains AT_HOLYWORD.  -b.t.
  330.  */
  331.  
  332. int tailor_god_spell(object *spellop, object *caster, int godnr) {
  333.     int caster_is_spell=0; 
  334.  
  335.     if(caster->type==FBULLET
  336.        ||caster->type==CONE
  337.        ||caster->type==FBALL) caster_is_spell=1; 
  338.  
  339.     if(!caster_is_spell)
  340.         if(godnr<0||((spellop->attacktype&AT_HOLYWORD)&&
  341.              !strcmp(Gods[godnr].enemy_race,"none"))) {
  342.           new_draw_info(NDI_UNIQUE, 0, caster,
  343.             "This prayer is useless unless you worship an appropriate god");
  344.           free_object(spellop);
  345.           return 0;
  346.         }
  347.  
  348.     /* either holy word or godpower attacks will set the slaying field */
  349.     if(spellop->attacktype&AT_HOLYWORD||spellop->attacktype&AT_GODPOWER) { 
  350.          if(spellop->slaying) free_string(spellop->slaying);
  351.          if(!caster_is_spell)
  352.             spellop->slaying = add_string(Gods[godnr].enemy_race);
  353.      else if(caster->slaying) 
  354.         spellop->slaying = add_string(caster->slaying);
  355.     }
  356.  
  357.     /* only the godpower attacktype adds the god's attack onto the spell */
  358.     if((spellop->attacktype&AT_GODPOWER)&&!caster_is_spell) 
  359.          spellop->attacktype=spellop->attacktype|Gods[godnr].attacktype;
  360.  
  361.     /* a little cosmetic for fun, we tack on the god's name to the spell */
  362.     if(spellop->attacktype&AT_HOLYWORD||spellop->attacktype&AT_GODPOWER) { 
  363.          if(spellop->title) free_string(spellop->title);
  364.          if(caster_is_spell&&caster->title) 
  365.            spellop->title=add_string(caster->title);
  366.          else if((godnr=get_god(caster))!=-1) 
  367.            spellop->title=add_string(Gods[godnr].name);
  368.          if(spellop->title){
  369.        char buf[MAX_BUF]; 
  370.        sprintf(buf,"%s of %s",spellop->name,spellop->title);
  371.        spellop->name=add_string(buf);
  372.     }
  373.     } 
  374.  
  375.     return 1;
  376. }
  377.  
  378.